﻿using System.Collections.Generic;
using System.Linq;
using DotNet.HowToUseInterfacesDemo.GoodUse.Models;

namespace DotNet.HowToUseInterfacesDemo.GoodUse.Repositories
{
    /// <summary>
    /// This is an example repository class
    /// </summary>
    public interface IPersonRepository
    {
        List<Person> GetAll();
        Person GetById(int id);
    }
    
    public class PersonRepository : IPersonRepository
    {
        public List<Person> GetAll()
        {
            return new List<Person>
            {
                new Person
                {
                    FirstName = "Jack", 
                    LastName = "Bauer", 
                    MethodOfContact = MethodOfContact.TextMessage
                },
                new Person
                {
                    FirstName = "Michael", 
                    LastName = "Weston",
                    MethodOfContact = MethodOfContact.Email
                },
                new Person
                {
                    FirstName = "Patrick", 
                    LastName = "Jane", 
                    MethodOfContact = MethodOfContact.Email
                }
            };
        }

        public Person GetById(int id)
        {
            return GetAll().FirstOrDefault(i => i.Id == id);
        }
    }
}
